package com.ding.manager.controller.user;

import com.ding.manager.controller.base.ManagerBaseController;
import com.ding.manager.service.ApproveService;
import com.ding.manager.util.ConstantMsgUtil;
import com.ding.manager.util.PageData;
import com.ding.manager.util.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 立项申请
 */
@Controller
@RequestMapping(value = "/instance")
public class DTInstanceController extends ManagerBaseController {

    @Resource(name = "approveService")
    private ApproveService approveService;

    @RequestMapping(value = "/create",produces="application/json")
    @ResponseBody
    public ResponseEntity create(){

        ResponseEntity responseEntity = new ResponseEntity();
        PageData pd = this.getPageData();
        try {
            approveService.insertInstance(pd);
        } catch (Exception e) {
            logger.info("新建立项申请失败", e);
            responseEntity.setMsg("新建立项申请失败!");
            responseEntity.setStatus(ConstantMsgUtil.getFailStatus());
        }
        return responseEntity;
    }

    /**
     * 导入立项申请
     * @return
     */
    @RequestMapping(value = "/push",produces="application/json")
    @ResponseBody
    public ResponseEntity push(){

        ResponseEntity responseEntity = new ResponseEntity();
        PageData pd = this.getPageData();
        try {
            approveService.insertProj(null,true);
        } catch (Exception e) {
            logger.info("新建立项申请失败", e);
            responseEntity.setMsg("新建立项申请失败!");
            responseEntity.setStatus(ConstantMsgUtil.getFailStatus());
        }
        return responseEntity;
    }





}
